<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="联系人" prop="noticeTitle">
        <el-input
          v-model="queryParams.name"
          placeholder="输入姓名查找"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="联系方式" prop="noticeTitle">
        <el-input
          v-model="queryParams.phone"
          placeholder="输入号码查找"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-table  :data="noticeList">
      <el-table-column label="序号" align="center">
        <template slot-scope="scope">{{scope.$index+1}}</template>
      </el-table-column>
      <el-table-column
        label="联系人"
        align="center"
        prop="name"
      />
      <el-table-column label="联系电话" align="center" prop="phone" />
      <el-table-column label="留言" align="center" prop="info">
        <template slot-scope="scope">
          <span class="info">{{scope.row.info}}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime">
        <template slot-scope="scope">
          <span>{{scope.row.createTime}}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >查看</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 查看 -->
    <el-dialog title="查看详情" :visible.sync="open" width="780px" append-to-body>
      <el-form ref="form" :model="form" label-width="80px">
        <el-row>
          <el-col :span="20">
            <el-form-item label="联系人" prop="noticeTitle">
              <el-input v-model="form.name" placeholder="请输入公告标题" />
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="电话" prop="noticeTitle">
              <el-input v-model="form.phone" placeholder="请输入公告标题" />
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="留言">
              <textarea disabled cols="82" rows="10" v-model="form.info"></textarea>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { infoList,delInfo } from "@/api/systemSettings/notice";
export default {
  name: "infoList",
  components: {
    
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 公告表格数据
      noticeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      multipleSelection:[],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name:null,
        phone:null
      },
      // 表单参数
      form: {},
    };
  },
  filters: {
    formatDate: function (value) {
        let date = new Date(parseInt(value) * 1000)
        let y = date.getFullYear();
        let m = date.getMonth() + 1;
        m = m < 10 ? ('0' + m) : m;
        let d = date.getDate();
        d = d < 10 ? ('0' + d) : d;
        let h = date.getHours();
        h = h < 10 ? ('0' + h) : h;
        let minute = date.getMinutes();
        let second = date.getSeconds();
        minute = minute < 10 ? ('0' + minute) : minute;
        second = second < 10 ? ('0' + second) : second;
        return  y + '-' + m + '-' + d + ' '+ h + ':' + minute + ':' + second
    }
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      infoList(this.queryParams).then((res) => {
          console.log(res)
            if(res.code == 200){
                this.noticeList=res.rows;
                this.total=res.total
            }           
        })
        .catch(() => {
            console.log('error submit!!');
            return false;
        });
    },
    handleUpdate(row){
      this.form=row;
      this.open=true
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 多选框选中数据
    // handleSelectionChange(selection) {
    //   this.ids = selection.map(item => item.noticeId)
    // },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$confirm('是否确认删除该数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delInfo(row.id);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    }
  }
};
</script>
<style lang="scss" scoped>
textarea{
    // width: 95%;
    box-sizing: border-box;
    padding: 5px;
    color: #666;
    resize:vertical;
}
.info{
  white-space: nowrap;
 overflow: hidden;
 text-overflow: ellipsis;
}
</style>